<template>
	<z-paging ref="paging" v-model="astralList" @query="queryList" :show-loading-more-no-more-view="false">
		<template slot="top">
			<cl-navbar :title="$t('astral.index.title')" leftIconSize="40rpx" placeholder :autoBack="false" leftIcon="">
			</cl-navbar>
			<view class="searchview">
				<u-search height="64rpx" :showAction="false" :clearabled="false" bgColor="#ffffff"
					:inputStyle="{fontSize:'24rpx'}" :placeholder="$t('commonality.search')"
					@input="searchInput"></u-search>
			</view>
			<view style="padding: 0 30rpx;">
				<u-swiper radius="40rpx" :list="swiperlist">
					<template v-slot:image="{ item, index }">
						<cl-stars-image :srckey="item.image_url"></cl-stars-image>
					</template>
				</u-swiper>
			</view>
		</template>
		<view class="box">
			<view class="list">
				<view class="list-items" v-for="(item, index) in searchlist" :key="index" @click="godetails(item)">
					<view class="">
						<cl-stars-image :srckey="item.cover_url"
							imageStyle="width: 290rpx;height: 260rpx;border-radius: 20px;"></cl-stars-image>
					</view>
					<view class="section">
						<view>
							<view class="section__topview u-line-2">
								<text class="section__topview__remai">{{item.cate_name}}</text>
								<text class="section__topview__nickname" v-html="item.product_name"></text>
							</view>
							<view class="section__tagview">
								<view class="section__tagview__tag" v-for="(tag,idx) in item.label_names"
									:key="index+'tag'+idx">
									<text class="section__tagview__tag__text">{{tag}}</text>
								</view>
							</view>
						</view>
						<view class="section__bottomview">
							<view class="section__bottomview__imgview" v-if="item.images">
								<cl-stars-image :srckey="image"
									imageStyle="width: 70rpx;height: 70rpx;border-radius: 5px;"
									v-for="(image,imgidx) in item.images.slice(0, 3)" :key="imgidx"></cl-stars-image>
							</view>
							<view class="section__bottomview__callview">
								<text class="section__bottomview__callview__text">{{$t('astral.index.orderNow')}}</text>
								<image class="section__bottomview__callview__xin" src="/static/icon/dazhaohuxin.svg" />
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<template slot="bottom">
			<cl-tabbar :currentTab="1"></cl-tabbar>
		</template>
	</z-paging>
</template>

<script>
	export default {
		name: 'astral',
		data() {
			return {
				swiperlist: [],
				astralList: [],
				constants: {},
				searchval: ''
			};
		},
		onLoad() {
			uni.hideTabBar()
			this.getList()
		},
		computed: {
			searchlist() {
				let newdata = this.astralList.filter(item => {
					// 根据名字筛选
					if (this.searchval && item.product_name.indexOf(this.searchval) === -1) {
						return false;
					}
					return true;
				});
				return newdata
			}
		},
		methods: {
			searchInput(e) {
				uni.$u.debounce(() => {
					this.searchval = e
				}, 500, false)
			},
			async queryList(pageNo, pageSize) {
				try {
					let res = await this.$api.common.starsProductsList({
						page: pageNo,
						limit: pageSize
					})
					if (res) {
						this.$refs.paging.complete(res.data.list)
					} else {
						this.$refs.paging.complete(false)
					}
				} catch (e) {
					this.$refs.paging.complete(false)
				}
			},
			getList() {
				this.$api.common.StarsBanner({
					banner_type: 1
				}).then(res => {
					if (res) {
						this.swiperlist = res.data.list
					}
				})
			},
			godetails(item) {
				this.$Router.push({
					name: 'astraldetails',
					params: {
						id: item.id
					}
				})
			}
		},
	};
</script>

<style scoped lang="scss">
	.searchview {
		margin: 20rpx 30rpx;
		background-color: #ffffff;
		border-radius: 60rpx;
		padding-right: 20rpx;
	}

	.box {
		padding: 0 30rpx;
		.list {
			margin: 20rpx 0 0 0;
			.list-items {
				background-color: rgba(30, 31, 48, 1);
				border-radius: 20px;
				margin-bottom: 30rpx;
				display: flex;
	
				.section {
					margin: 20rpx 0 15rpx 0;
					padding: 0 25rpx 0 20rpx;
					display: flex;
					flex: 1;
					overflow: hidden;
					flex-direction: column;
					justify-content: space-between;
	
					&__topview {
						// display: flex;
						line-height: 1.2;
						&__remai {
							// align-self: self-start;
							background: #FF605F;
							border-radius: 10rpx;
							padding: 3rpx 10rpx;
							font-size: 20rpx;
							margin-right: 10rpx;
						}
	
						&__nickname {
							// overflow-wrap: break-word;
							color: #fff;
							font-size: 28rpx;
						}
					}
	
					&__tagview {
						display: flex;
						gap: 10rpx;
						margin-top: 28rpx;
	
						&__tag {
							display: flex;
							border-radius: 11px;
							padding: 3rpx 10rpx;
							background: #C7964F;
	
							&__text {
								overflow-wrap: break-word;
								color: rgba(255, 255, 255, 1);
								font-size: 20rpx;
							}
						}
					}
	
					&__detail {
						overflow-wrap: break-word;
						color: #61626E;
						font-size: 24rpx;
					}
	
					&__bottomview {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
	
						&__imgview {
							display: flex;
							gap: 10rpx;
						}
	
						&__callview {
							justify-self: end;
							background-color: rgba(18, 19, 37, 1);
							border-radius: 10px;
							position: relative;
							padding: 8rpx 20rpx 8rpx 20rpx;
							align-self: flex-end;
							display: flex;
							align-items: center;
							justify-content: center;
	
							&__text {
								background-image: linear-gradient(180deg,
										rgba(255, 255, 255, 1) 0,
										rgba(182, 139, 77, 1) 100%);
								overflow-wrap: break-word;
								color: rgba(255, 255, 255, 1);
								font-size: 24rpx;
								-webkit-background-clip: text;
								-webkit-text-fill-color: transparent;
							}
	
							&__xin {
								position: absolute;
								right: 0rpx;
								top: -25rpx;
								width: 40rpx;
								height: 40rpx;
							}
						}
					}
				}
			}
		}
	}
</style>